package net.mingsoft.report_data.biz.impl.report_gen;

import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import net.mingsoft.report_data.biz.ZkDataSgSqBiz;
import net.mingsoft.report_data.dao.ZkDataSgSqDao;
import net.mingsoft.report_data.entity.S02PopuAgeStruEntity;
import net.mingsoft.report_data.entity.S02PopuTotalSituEntity;
import net.mingsoft.report_data.entity.S02ProHgjj001Entity;
import net.mingsoft.report_data.entity.vo.TimeCountDto;
import net.mingsoft.report_data.util.MathUtil;
import net.mingsoft.report_data.util.PeriodUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 社管申请的表
 *
 * @author gengfa
 * @date 2022/06/08
 */
@Service
@DS(value = "zw")
public class ZkDataSgSqBizImpl implements ZkDataSgSqBiz {

    @Resource
    ZkDataSgSqDao sgSqDao;

    @Override
    public Map<String, Object> getPopulationFlowAndEconomicMetric(Map<String, Object> map) {
        // 获取时间区间数据
        final String beginDate = (String) map.get("beginDate");
        final String endDate = (String) map.get("endDate");
        List<S02PopuTotalSituEntity> entities
                = sgSqDao.selectPopulationData(beginDate.substring(0, 10), endDate.substring(0, 10));
        S02ProHgjj001Entity s02ProHgjj001Entity = sgSqDao.selectLastGDPData();
        List<TimeCountDto> hainanPermanentPopulationDtoList = new ArrayList<>();
        List<TimeCountDto> hainanGdpDtoList = new ArrayList<>();
        for (S02PopuTotalSituEntity entity : entities) {
            hainanPermanentPopulationDtoList.add(new TimeCountDto().setTime(entity.getDataDtIso()).setCount(MathUtil.getTenThousand(entity.getPmntPopuNum())));
            hainanGdpDtoList.add(new TimeCountDto().setTime(entity.getDataDtIso()).setCount(String.valueOf(s02ProHgjj001Entity.getShjjhgjj001Y())));
        }
        map.put("hainanPermanentPopulationDtoList", JSON.toJSONString(hainanPermanentPopulationDtoList));
        map.put("hainanGdpDtoList", JSON.toJSONString(hainanGdpDtoList));
        return map;
    }

    @Override
    public S02ProHgjj001Entity getGDPData() {
        return sgSqDao.selectLastGDPData();
    }

    @Override
    public List<S02PopuAgeStruEntity> getAgeData() {
        return sgSqDao.selectLastAgePopulationData();
    }
}
